package com.yunji.cabinet.service.impl;

import com.yunji.base.bo.ChangeBindBO;
import com.yunji.cabinet.bo.CabinetCellListQueryBO;
import com.yunji.cabinet.bo.CabinetTemplateBO;
import com.yunji.cabinet.dao.ICabinetTemplateCellDao;
import com.yunji.cabinet.dao.ICabinetTemplateDao;
import com.yunji.cabinet.domain.CabinetTemplateDO;
import com.yunji.cabinet.domain.CabinetTemplateCellDO;
import com.yunji.cabinet.dto.CabinetFiledDTO;
import com.yunji.cabinet.mapper.CabinetTemplateCellMapper;
import com.yunji.cabinet.service.ICabinetTemplateService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.cabinet.service.impl
 * @FileName CabinetTemplateServiceImpl.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-04-07 16:57:54
 * @Description 货柜模板接口实现
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-07 16:57:54		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@Service
public class CabinetTemplateServiceImpl implements ICabinetTemplateService {

    @Resource
    private CabinetTemplateCellMapper templateCellMapper;

    @Resource
    private ICabinetTemplateDao cabinetTemplateDao;

    @Resource
    private ICabinetTemplateCellDao cabinetTemplateCellDao;

    /**
     * @param id 货柜模板ID
     * @return CabinetTemplate 货柜模板信息详情
     * @Title select
     * @Intro 获取货柜模板信息详情
     * @Date 2024-06-09 23:05:25.202
     */
    @Override
    public CabinetTemplateBO select(Long id) {
        CabinetTemplateDO template = cabinetTemplateDao.getById(id);
        List<CabinetTemplateCellDO> cellList = cabinetTemplateCellDao.searchTemplateCells(CabinetCellListQueryBO.builder().templateId(id).build());
        CabinetTemplateBO bo = new CabinetTemplateBO();
        bo.setCabinetTemplate(template);
        bo.setCellList(cellList);
        return bo;
    }


    @Override
    public CabinetTemplateDO getById(Long templateId) {
        return cabinetTemplateDao.getById(templateId);
    }

    /**
     * @param template 货柜模板信息
     * @return boolean 创建结果
     * @Title create
     * @Intro 创建货柜模板信息
     * @Date 2024-06-09 23:06:20.799
     */
    @Override
    public boolean create(CabinetTemplateDO template) {
        return cabinetTemplateDao.save(template);
    }

    /**
     * @param template 货柜模板信息
     * @return boolean 更新结果
     * @Title update
     * @Intro 更新货柜模板信息
     * @Date 2024-06-09 23:06:54.270
     */
    @Override
    public boolean update(CabinetTemplateDO template) {
        return cabinetTemplateDao.updateById(template);
    }

    /**
     * @param map 更新参数
     * @Title changeAgent
     * @Desc 切换代理
     * @Date 2024-09-13 19:24:10.466
     * @Return boolean 更新结果
     */
    @Override
    public boolean changeAgent(ChangeBindBO bo) {
        return cabinetTemplateDao.changeAgent(bo);
    }

    /**
     * @param ids 货柜模板ID数组
     * @return boolean 删除结果
     * @Title delete
     * @Intro 删除货柜模板信息
     * @Date 2024-06-09 23:01:34.421
     */
    @Override
    public boolean delete(Long... ids) {
        return cabinetTemplateDao.removeByIds(Arrays.asList(ids));
    }

    /**
     * @param params 过滤条件
     * @Title searchTableField
     * @Desc 查找表字段信息
     * @Date 2024-08-26 14:00:27.048
     * @Return List<String> 匹配数据信息
     */
    @Override
    public List<String> searchTableField(CabinetFiledDTO params) {
        return cabinetTemplateDao.searchTableField(params);
    }

}
